/*
 * main.cpp
 * Description: QT based Gui panel for POW system
 *
 * Copyright (c) 2013, Centre for Intelligent Mechatronics Systems, University of Technology, Sydney, Australia.
 * All rights reserved.
 *
 * This software was developed as a part of an industry based research project on Assistive Robotic Devices.
 *
 * Author: Bojan Andonovski
 * Date: 25/01/2013
 *
 * Rev History:
 *       0.0 -Bojan Andonovski
 */


#include <QtGui>
#include <QApplication>
#include "pow_gui/samplingthread.hpp"
#include "pow_gui/main_window.hpp"

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_grid.h>
#include <qwt_symbol.h>
#include <qwt_legend.h>
/*****************************************************************************
** Main
*****************************************************************************/

int main(int argc, char **argv) {

	//Roslaunch
	QProcess process,process1;
	process.start("roslaunch", QStringList() << "/home/bojan/svn/POW/ROS/Fuerte/utils/pow_analyzer/launch/pow_analyze_hector_assess.launch");
	//process1.start("/bin/sh", QStringList() << "/home/bojan/svn/POW/ROS/Fuerte/utils/matlab_run.sh");
	//GUI
    QApplication app(argc, argv);
    pow_gui::MainWindow w(argc,argv);
/*
    //w.show();
       ///////////////////////////////////////////
        //QWidget * plot = ui.plotgraph;
    QwtPlot plot;
   // QwtPlotPlot *plot=new QwtPlotPlot(); //Create plot widget
    plot.setTitle( "Plot LinVel" );
    plot.setCanvasBackground( Qt::white );
    // Axis
    plot.setAxisTitle( QwtPlot::xBottom, "Time(sec)" );
    plot.setAxisTitle( QwtPlot::yLeft, "Linear Velocity (m/sec)" );
    plot.setAxisScale( QwtPlot::yLeft, 0.0, 10.0 );
    plot.setAxisScale( QwtPlot::xBottom, 0.0, 50.0 );
    plot.insertLegend( new QwtLegend() );

    //samplingThread.start();
    QwtPlotGrid *grid = new QwtPlotGrid();
    grid->attach( &plot );

    QwtPlotCurve *curve = new QwtPlotCurve();
    curve->setTitle( "Linear velocity" );
    // Set curve styles
    curve->setPen( Qt::blue, 4 ),
    curve->setRenderHint( QwtPlotItem::RenderAntialiased, true );

    QwtSymbol *symbol = new QwtSymbol( QwtSymbol::Ellipse,
    QBrush( Qt::yellow), QPen( Qt::red, 2 ), QSize( 8, 8 ) );
    curve->setSymbol( symbol);
  
    // Assign values to the curve     
    curve->setSamples(w.get_linv_g());//yaw_g,trav_g,wall_g;
    curve->attach( &plot );

    plot.resize( 600, 400 );
    plot.show();
*/
    // ros::Duration d(1); while(ros::ok()) d.sleep();
	   w.show();
    app.connect(&app, SIGNAL(lastWindowClosed()), &app, SLOT(quit()));
    //ROS_WARN("				EXECUTING APP------------------------------");
    int result = app.exec();
   
    std::cout << "q application finished" << std::endl;

	return result;
}
